<?php
class Paymentmessages extends MY_Controller {
	var $currentPage = 'paymentmessages';
	var $caption = 'Paymentmessages';
	var $action = '';
	
	public function index() {
		
		$data['paymentmessageslist'] = $this->mPaymentMessages->getAllEntries();
		
		$this->loadAdminPage($data);
		
	}
	
	public function create($data='') {
		$this->action = 'add';
		
		$this->loadAdminPage($data);
	}
	
	public function add() {
		$paymentmessages = $this->mPaymentMessages;
		
		$paymentmessages->online_payment = trim($this->input->post('online_payment',TRUE));
		$paymentmessages->bank_transfer = trim($this->input->post('bank_transfer',TRUE));
		$paymentmessages->western_union = trim($this->input->post('western_union',TRUE));
		
		
		$this->message = INSERT_ERROR;
		
		if(strlen($paymentmessages->online_payment) != 0 && strlen($paymentmessages->bank_transfer) != 0 && strlen($paymentmessages->western_union) != 0) {
			
			//if(count($this->mBusinessnature->find_by_code($businessnature->code))==0) {
				$this->message = INSERT_SUCCESS;
				$paymentmessages->insert();	
			//} else {
			//	$this->message = HAS_DUPLICATE . " code.";
			
			//	$data['businessnature'] = $businessnature;
				
			//	$this->create($data);
				
			//	return;
			//}
		}
		
		$this->index();
	}
	
	public function edit($id) {
		 
		$paymentmessages = $this->mPaymentMessages->getEntryById($id);
		
		if(count($paymentmessages) == 0) {
			show_error("Invalid payment messages", 500, "Invalid data");
		}
	
		$data['paymentmessages'] = $paymentmessages[0];
		
		$this->action = 'edit';
		$this->id = $paymentmessages[0]->id;
		$this->loadAdminPage($data);
	}
	
	public function update() {
		
		$paymentmessages = $this->mPaymentMessages;
		
		$paymentmessages->id = $this->input->post('id',TRUE);
		$paymentmessages->online_payment = trim($this->input->post('online_payment',TRUE));
		$paymentmessages->bank_transfer = trim($this->input->post('bank_transfer',TRUE));
		$paymentmessages->western_union = trim($this->input->post('western_union',TRUE));
		
		$this->message = UPDATE_ERROR;
		
		if(strlen($paymentmessages->id) != 0 && strlen($paymentmessages->online_payment) != 0 && strlen($paymentmessages->bank_transfer) != 0 && strlen($paymentmessages->western_union) != 0) {
			
			//if(count($this->mBusinessnature->find_by_code_of_others($businessnature->id,$businessnature->code))==0) {
				if($paymentmessages->update())
					$this->message = UPDATE_SUCCESS;
			//} else {
			//	$this->message = HAS_DUPLICATE . " code.";
			//}
		}
		
		$this->edit($paymentmessages->id);
	}
	
	public function delete($id) {
		
		$this->message = DELETE_ERROR;
		
		if($this->mPaymentMessages->delete($id))
			$this->message = DELETE_SUCCESS;
		
		$this->index();
	}
}

?>